//
//  DHWashingController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/14.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHWashingController.h"
#import "DHWashingCell.h"

@interface DHWashingController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *itemArr;
@property (assign, nonatomic) NSInteger pageIndex;

@end

@implementation DHWashingController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"衣服清洗";
    
    [self.tableView registerNib:[UINib nibWithNibName:@"DHWashingCell" bundle:nil] forCellReuseIdentifier:kDHWashingCell];
    self.tableView.mj_header = [DHMJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    [self loadData];
}

- (NSMutableArray *)itemArr{
    if (!_itemArr) {
        _itemArr = [NSMutableArray array];
    }
    return _itemArr;
}

- (void)loadData{
    [[DHNetAPIClient shareDHNetAPIClient] request_categoriesWithParams:@{@"sex":@"男"} andBlock:^(id data, NSError *error) {
        [self.tableView.mj_header endRefreshing];
        [self.itemArr removeAllObjects];
        [self.itemArr addObjectsFromArray:[data objectForKey:@"categories"]];
        [self.tableView reloadData];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - tableview
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.itemArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 90;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DHWashingCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHWashingCell forIndexPath:indexPath];
    [cell updateCell:[self.itemArr objectAtIndex:indexPath.row]];
    return cell;
}

@end
